from fastapi import Request
import time

from util.log import Log

async def process_time(request: Request, next):
    Log.debug(f'request 进入 [process_time] 中间件')
    start = time.time() * 1000
    response = await next(request)
    end = time.time() * 1000
    Log.debug('response 离开 [process_time] 中间件')
    response.headers["process-time"] = str(int(end - start)) + 'ms'
    return response